package com.linpq.road.controller;

import java.io.IOException;
import java.util.List;

import com.linpq.common.core.domain.entity.SysUser;
import com.linpq.common.utils.ShiroUtils;
import com.linpq.road.domain.RdRoadSection;
import com.linpq.road.domain.Roadsection;
import com.linpq.road.service.RdRoadSectionService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.linpq.common.annotation.Log;
import com.linpq.common.enums.BusinessType;
import com.linpq.road.domain.RdRoadSectionLane;
import com.linpq.road.service.RdRoadSectionLaneService;
import com.linpq.common.core.controller.BaseController;
import com.linpq.common.core.domain.AjaxResult;
import com.linpq.common.utils.poi.ExcelUtil;
import com.linpq.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 路桩车道Controller
 *
 * @author linpq
 * @date 2021-07-29
 */
@Controller
@RequestMapping("/road/road_section_lane")
public class RdRoadSectionLaneController extends BaseController {
    private String prefix = "road/road_section_lane";

    @Autowired
    private RdRoadSectionLaneService rdRoadSectionLaneService;

    @Autowired
    private RdRoadSectionService rdRoadSectionService;

    @RequiresPermissions("road:road_section_lane:view")
    @GetMapping()
    public String road_section_lane() {
        return prefix + "/road_section_lane";
    }

    /**
     * 查询路桩车道列表
     */
    @RequiresPermissions("road:road_section_lane:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(RdRoadSectionLane rdRoadSectionLane,ModelMap map) {
        startPage();
        List<RdRoadSection> rdRoadSectionList = rdRoadSectionService.selectRdRoadSectionList(new RdRoadSection());
        map.put("roadSectionList",rdRoadSectionList);
        List<RdRoadSectionLane> list = rdRoadSectionLaneService.selectRdRoadSectionLaneList(rdRoadSectionLane);
        return getDataTable(list);
    }

//    @RequiresPermissions("road:road_section_lane:import")
//    @Log(title = "路桩车道", businessType = BusinessType.IMPORT)
//    @PostMapping("/import")
//    @ResponseBody
//    public AjaxResult rdRoadSectionLaneImport(MultipartFile file) throws Exception {
//        ExcelUtil<RdRoadSectionLane> util = new ExcelUtil<RdRoadSectionLane>(RdRoadSectionLane.class);
//        List<RdRoadSectionLane> rdRoadSectionLaneList = util.importExcel(file.getInputStream());
//        String message = rdRoadSectionLaneService.importRdRoadSectionLane(rdRoadSectionLaneList);
//        return AjaxResult.success(message);
//    }

    /**
     * 导出路桩车道列表
     */
    @RequiresPermissions("road:road_section_lane:export")
    @Log(title = "路桩车道", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(RdRoadSectionLane rdRoadSectionLane) {
        List<RdRoadSectionLane> list = rdRoadSectionLaneService.selectRdRoadSectionLaneList(rdRoadSectionLane);
        ExcelUtil<RdRoadSectionLane> util = new ExcelUtil<RdRoadSectionLane>(RdRoadSectionLane.class);
        return util.exportExcel(list, "road_section_lane");
    }

    /**
     * 新增路桩车道
     */
    @GetMapping("/add")
    public String add(ModelMap map) {
        List<RdRoadSection> rdRoadSectionList = rdRoadSectionService.selectRdRoadSectionList(new RdRoadSection());
        map.put("roadSectionList",rdRoadSectionList);
        return prefix + "/add";
    }

    /**
     * 新增保存路桩车道
     */
    @RequiresPermissions("road:road_section_lane:add")
    @Log(title = "路桩车道", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(RdRoadSectionLane rdRoadSectionLane) {
        return toAjax(rdRoadSectionLaneService.insertRdRoadSectionLane(rdRoadSectionLane));
    }

    /**
     * 修改路桩车道
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap) {
        RdRoadSectionLane rdRoadSectionLane = rdRoadSectionLaneService.selectRdRoadSectionLaneById(id);
        mmap.put("rdRoadSectionLane", rdRoadSectionLane);
        return prefix + "/edit";
    }

    /**
     * 修改保存路桩车道
     */
    @RequiresPermissions("road:road_section_lane:edit")
    @Log(title = "路桩车道", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(RdRoadSectionLane rdRoadSectionLane) {
        return toAjax(rdRoadSectionLaneService.updateRdRoadSectionLane(rdRoadSectionLane));
    }

    /**
     * 删除路桩车道
     */
    @RequiresPermissions("road:road_section_lane:remove")
    @Log(title = "路桩车道", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(rdRoadSectionLaneService.deleteRdRoadSectionLaneByIds(ids));
    }
}
